import requests
from PySide6.QtCore import QThread, Signal
from settings import HOST


class WechatLinkmanListThread(QThread):
    error_signal = Signal(str)
    success_signal = Signal(dict)

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.pull_type = 1

    def set_pull_type(self, pull_type):
        self.pull_type = pull_type

    def run(self):
        try:
            r = requests.post(HOST, json={'type': 5, 'pull_type': self.pull_type})
            data = r.json()
            if data['errno'] == 0:
                self.success_signal.emit(data['data'])
        except Exception as e:
            self.error_signal.emit(str(e))
